package com.ev.apis.controller.asl;

import com.ev.framework.annotation.EvApiByToken;
import com.ev.framework.utils.R;
import com.ev.asl.config.JiateConstant;
import com.ev.asl.service.KisBasicsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 金蝶KIS同步API   加特 同步KIS旗舰版
 */
@Api(value = "/", tags = "同步KIS API----基础基础资料 ")
@RestController
public class KisBasicsSyncApiController {

    @Resource
    private KisBasicsService kisBasicsService;

    @EvApiByToken(value = "/apis/KisSync/baseInfo/getMaterielAll", method = RequestMethod.GET)
    @ApiOperation("物料--同步全部信息,同一个用户操作间隔控制在90秒内")
    public R materielSync() {
        try {
            return kisBasicsService.materielDataByParam(JiateConstant.MATERIEL);
        } catch (Exception ex) {
            return R.error("同步失败，请稍后重试或联系管理员，失败原因:"+ex.getMessage());
        }
    }

    @Transactional(rollbackFor = Exception.class)
    @EvApiByToken(value = "/apis/KisSync/baseInfo/getWarehouseAll", method = RequestMethod.GET)
    @ApiOperation("仓库--同步全部信息,同一个用户操作间隔控制在60秒内")
    public R wareHouseSync() {
        try {
            return kisBasicsService.wareHouseDataByParam(JiateConstant.WAREHOUSE_OR_LOCATION);
        } catch (Exception ex) {
            return R.error("同步失败，请稍后重试或联系管理员，失败原因:"+ex.getMessage());
        }
    }

    @EvApiByToken(value = "/apis/KisSync/baseInfo/getFreightSpaceAll", method = RequestMethod.GET)
    @ApiOperation("仓位--同步全部信息,同一个用户操作间隔控制在60秒内")
    public R freightSpaceSync() {
        try {
            return kisBasicsService.freightSpaceByParam(JiateConstant.WAREHOUSE_OR_LOCATION);
        } catch (Exception ex) {
            return R.error("仓位同步失败，请稍后重试或联系管理员，失败原因:"+ex.getMessage());
        }
    }

    @EvApiByToken(value = "/apis/KisSync/baseInfo/getUserAll", method = RequestMethod.GET)
    @ApiOperation("用户--同步全部信息,同一个用户操作间隔控制在60秒内")
    public R userSync() {
        try {
            return kisBasicsService.userDataByParam(JiateConstant.USERS);
        } catch (Exception ex) {
            return R.error("同步失败，请稍后重试或联系管理员，失败原因:"+ex.getMessage());
        }
    }

    @EvApiByToken(value = "/apis/KisSync/baseInfo/getClientAll", method = RequestMethod.GET)
    @ApiOperation("客户--同步全部信息,同一个用户操作间隔控制在60秒内")
    public R clientSync() {
        try {
            return kisBasicsService.clientDataByParam(JiateConstant.CLIENT);
        } catch (Exception ex) {
            return R.error("客户同步失败，请稍后重试或联系管理员，失败原因:"+ex.getMessage());
        }
    }

    @EvApiByToken(value = "/apis/KisSync/baseInfo/getSupplierAll", method = RequestMethod.GET)
    @ApiOperation("供应商--同步全部信息,同一个用户操作间隔控制在60秒内")
    public R supplierSync() {
        try {
            return kisBasicsService.supplierDataByParam(JiateConstant.SUPPLIER);
        } catch (Exception ex) {
            return R.error("供应商同步失败，请稍后重试或联系管理员，失败原因:"+ex.getMessage());
        }
    }

    @EvApiByToken(value = "/apis/KisSync/baseInfo/getDepartAll", method = RequestMethod.GET)
    @ApiOperation("部门--同步全部信息,同一个用户操作间隔控制在60秒内")
    public R departSync() {
        try {
            return kisBasicsService.departDataByParam(JiateConstant.DEPART);
        } catch (Exception ex) {
            return R.error("部门同步失败，请稍后重试或联系管理员，失败原因:"+ex.getMessage());
        }
    }

    @Transactional(rollbackFor = Exception.class)
    @EvApiByToken(value = "/apis/KisSync/baseInfo/getDictionaryUnitAll", method = RequestMethod.GET, apiTitle = "基础信息-同步全部计量单位信息")
    @ApiOperation("计量单位--同步全部计量单位信息")
    public R unitSync() {
        R r = kisBasicsService.unitOfMeasurement();
        System.out.println("-----------------异步方法后打印" );
        return R.ok();
    }

}
